package com.leezk.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.leezk.order.constant.CommonConstant;
import com.leezk.order.dto.ResultDTO;
import com.leezk.order.entity.Menu;
import com.leezk.order.service.IMenuService;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.xml.transform.Result;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author leotong
 * @since 2022-03-16
 */
@RestController
@RequestMapping(CommonConstant.API_URI_VERSION_V1+"/menu")
public class MenuController {
    @Autowired
    private IMenuService menuService;

    @GetMapping("/getMenus")
    public ResultDTO<Page<Menu>> getMenus(int pageNum,int pageSize){
        Page<Menu> page=new Page<>(pageNum,pageSize);
        return ResultDTO.success(menuService.getMenus(page));
    }
    @GetMapping("/getAllMenus")
    public ResultDTO<List<Menu>> getAllMenus(){
        return ResultDTO.success(menuService.list());
    }

    @GetMapping("/getMenusByName")
    public ResultDTO<List<Menu>> getMenusByName(String name){
        return ResultDTO.success(menuService.getMenusByName(name));
    }
    @PostMapping("/addMenus")
    public ResultDTO<Boolean> addMenu(@RequestBody Menu menu){
        return ResultDTO.success(menuService.save(menu));
    }

    @GetMapping("/deleteMenus")
    public ResultDTO<Boolean> deleteMenu(int id){
        return ResultDTO.success(menuService.removeById(id));
    }

    @PostMapping("/updateMenu")
    public ResultDTO<Boolean> updateMenu(@RequestBody Menu menu){
        menu.setCreateTime(new Date());
        return ResultDTO.success(menuService.updateById(menu));
    }
    @GetMapping("/getAddMenu")
    public ResultDTO<List<Menu>> getAddMenu(int id,String typeCode){
        return ResultDTO.success(menuService.getAddMenu(id,typeCode));
    }
    @GetMapping("/getMenuByDic")
    public ResultDTO<List<Menu>> getMenuByDic(int did){
        return ResultDTO.success(menuService.getMenuByDic(did));
    }
}
